package 设计模式.代理模式.动态代理;

import java.lang.reflect.Proxy;

public class ClientTest {
    public static void main(String[] args) {
        Movable tank=new Tank();
        //可以为所有对象产生时间代理的InvocationHandler
        MyTimeProxyInvocationHandler myTimeProxyInvocationHandler = new MyTimeProxyInvocationHandler(tank);
        MyLogProxyInvocationHandler myLogProxyInvocationHandler = new MyLogProxyInvocationHandler(tank);


        Movable tanktimeProxy =(Movable) Proxy.newProxyInstance(tank.getClass().getClassLoader(), tank.getClass().getInterfaces(),
                myTimeProxyInvocationHandler);
        Movable tanklogProxy=(Movable) Proxy.newProxyInstance(tank.getClass().getClassLoader(),tank.getClass().getInterfaces(),
                myLogProxyInvocationHandler );

        System.out.println("tank-------------");
        tanktimeProxy.move();
        tanklogProxy.move();

        //为飞机做代理
        Plane plane = new Plane();
        MyTimeProxyInvocationHandler myTimeProxyInvocationHandler1= new MyTimeProxyInvocationHandler(plane);
        Flyable planeProxy = (Flyable)Proxy.newProxyInstance(
                plane.getClass().getClassLoader(),
                plane.getClass().getInterfaces(),
                myTimeProxyInvocationHandler1
        );
        System.out.println("plane--------");
        planeProxy.fly();;


    }


}